package com.hongxun.design.jungong.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.hongxun.design.R;
import com.hongxun.design.activitys.BaseActivity;
import com.hongxun.design.fragments.BaseFragment;
import com.hongxun.design.jungong.fragment.FragmentMaterial;
import com.hongxun.design.mytools.MString;

/**
 * Created by Administrator on 2017/8/2.材料组装、随手拍
 */

public class Mainactivity_jg extends BaseActivity {
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;
    private FragmentMaterial material;
    private String type = "1";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jg_activity_main);
        myGetIntent();
    }

    @SuppressLint("NewApi")
    private void myGetIntent() {
        fragmentManager = getSupportFragmentManager();
        transaction = fragmentManager.beginTransaction();
        Bundle bundle = getIntent().getExtras();
        type = bundle.getString(MString.CODE, "1");
        material = new FragmentMaterial();
        if (type.equals("1")) {
            replaceFragment(material, type);
        } else {
            startActivity(new Intent(this, ProRecAndPicActivity.class));
            finish();
        }
    }

    private void replaceFragment(BaseFragment newFragment, String tag) {
        try {
            if (!newFragment.isAdded()) {
                transaction.add(R.id.activity_jg_fragment, newFragment, tag);
            } else {
                transaction.show(newFragment);
            }
            transaction.commit();
            newFragment.Refresh();
        } catch (Exception e) {
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (type.equals("1")) {
            material.onActivityResult(requestCode, resultCode, data);
        }
    }
}
